package java44th.group.service.wx.footprint;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketFootprint;
import java44th.group.bean.po.MarketUser;
import java44th.group.bean.wx.vo.footprint.WxFootPrintDeleteVO;
import java44th.group.bean.wx.vo.footprint.WxFootPrintVO;
import java44th.group.mapper.MarketFootprintMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @projectName: project-second
 * @package: java44th.group.service.wx.footprint
 * @className: WxFootPrintMServiceImpl
 * @author: 杨浩祥
 * @description: TODO
 * @date: 2022/10/16 14:37
 * @version: 1.0
 */
@Service
public class WxFootPrintServiceImpl implements WxFootPrintService {

    @Autowired
    MarketFootprintMapper footprintMapper;

    @Override
    public BaseRespVo list(BasePageInfo info) {
        // {"errno":0,"data":{"total":566,"pages":57,"limit":10,"page":1,"list":[{"brief":"安心舒适是最好的礼物","picUrl":"http://yanxuan.nosdn.127.net/1f67b1970ee20fd572b7202da0ff705d.png","addTime":"2022-10-16 14:39:13","goodsId":1181000,"name":"母亲节礼物-舒适安睡组合","id":2512,"retailPrice":2598.00},{"brief":"一等白鸭绒，蓬松承托","picUrl":"http://yanxuan.nosdn.127.net/29bc800b9f1fa551bc3cd47b10e2a799.png","addTime":"2022-10-16 14:37:26","goodsId":1075023,"name":"舒适安睡复合羽绒枕","id":2511,"retailPrice":199.00},{"brief":"很不错  很欧克","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/fexbwnidqlz50d8k9rgv.jpg","addTime":"2022-10-16 14:37:13","goodsId":1181137,"name":"管道","id":2510,"retailPrice":120.00},{"brief":"纯棉呵护，属于你我的记忆","picUrl":"http://yanxuan.nosdn.127.net/d7bd87f8cc1965b25be33a8aad53812b.png","addTime":"2022-10-16 14:25:02","goodsId":1064007,"name":"3D纯棉护颈双人记忆枕","id":2509,"retailPrice":249.00},{"brief":"这是商品简介","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/8718ftzpkmactshaivkg.jpg","addTime":"2022-10-16 14:02:44","goodsId":1181077,"name":"这是商品测试名称","id":2508,"retailPrice":0.00},{"brief":"这是商品简介","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/8718ftzpkmactshaivkg.jpg","addTime":"2022-10-16 13:57:23","goodsId":1181077,"name":"这是商品测试名称","id":2507,"retailPrice":0.00},{"brief":"1哈哈哈哈","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/bonazccbl0maembuooml.jpg","addTime":"2022-10-16 12:00:28","goodsId":1181085,"name":"111","id":2502,"retailPrice":99.00},{"brief":"","picUrl":"http://182.92.235.201:8083/wx/storage/fetch/psaje16kl4g4sw5ot4lb.jpg","addTime":"2022-10-16 11:29:20","goodsId":1181139,"name":"张三","id":2501,"retailPrice":100.00},{"brief":"纯棉呵护，属于你我的记忆","picUrl":"http://yanxuan.nosdn.127.net/d7bd87f8cc1965b25be33a8aad53812b.png","addTime":"2022-10-16 11:27:51","goodsId":1064007,"name":"3D纯棉护颈双人记忆枕","id":2500,"retailPrice":249.00},{"brief":"纯棉呵护，属于你我的记忆","picUrl":"http://yanxuan.nosdn.127.net/d7bd87f8cc1965b25be33a8aad53812b.png","addTime":"2022-10-16 11:25:20","goodsId":1064007,"name":"3D纯棉护颈双人记忆枕","id":2499,"retailPrice":249.00}]},"errmsg":"成功"}
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser)subject.getPrincipals().getPrimaryPrincipal();
        PageHelper.startPage(info.getPage(),info.getLimit());
        List<WxFootPrintVO> list = footprintMapper.selectWxFootPrintVOByUserId(marketUser.getId());
        PageInfo pageInfo = new PageInfo(list);
        return BaseRespVo.ok(CommonData.data(pageInfo));
    }

    @Transactional
    @Override
    public BaseRespVo delete(WxFootPrintDeleteVO wxFootPrintDeleteVO) {
        MarketFootprint marketFootprint = new MarketFootprint();
        marketFootprint.setId(wxFootPrintDeleteVO.getId());
        marketFootprint.setUpdateTime(new Date());
        marketFootprint.setDeleted(true);
        footprintMapper.updateByPrimaryKeySelective(marketFootprint);
        return BaseRespVo.ok();
    }
}
